package com.game.majiang.vo;

import java.sql.Types;
import java.util.ArrayList;

import javax.sql.rowset.CachedRowSet;

import com.game.server.db.Parameter;
import com.game.server.db.ParameterType;
import com.game.server.db.SqlHelper;
import com.game.server.db.SqlHelperwrite;
import com.game.server.db.entity.JiangliLog;

public class JiangliLogVo {

	public static void insertInto(int uid, int jianglitype, int gold, int paiming) {
		String sql = "INSERT INTO jianglilog (uid,jianglitype,gold,paiming) VALUES (?,?,?,?)";
		Parameter p1 = new Parameter(Types.INTEGER, uid, ParameterType.Input);
		Parameter p2 = new Parameter(Types.INTEGER, jianglitype, ParameterType.Input);
		Parameter p3 = new Parameter(Types.INTEGER, gold, ParameterType.Input);
		Parameter p4 = new Parameter(Types.INTEGER, paiming, ParameterType.Input);
		SqlHelperwrite.execute(sql, p1,p2,p3,p4);
	}
	
	public static ArrayList<JiangliLog> selectUser(int uid, int jianglitype) {
		ArrayList<JiangliLog> list = new ArrayList<>();
		String sql = "SELECT id,uid,jianglitype,gold,createtime FROM jianglilog WHERE uid = ? AND jianglitype = ? ORDER BY createtime DESC";
		Parameter p1 = new Parameter(Types.INTEGER, uid, ParameterType.Input);
		Parameter p2 = new Parameter(Types.INTEGER, jianglitype, ParameterType.Input);
		CachedRowSet resultSet = SqlHelper.getResultSet(sql, p1,p2);
		try {
			while (resultSet.next()) {
				JiangliLog jll = new JiangliLog();
				jll.id = resultSet.getInt("id");
				jll.uid = resultSet.getInt("uid");
				jll.jianglitype = resultSet.getInt("jianglitype");
				jll.gold = resultSet.getInt("gold");
				jll.createtime = resultSet.getString("createtime");
				list.add(jll);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
	public static ArrayList<JiangliLog> selectUser(int uid, int jianglitype1, int jianglitype2) {
		ArrayList<JiangliLog> list = new ArrayList<>();
		String sql = "SELECT id,uid,jianglitype,gold,createtime,paiming FROM jianglilog WHERE uid = ? AND (jianglitype = ? OR jianglitype=?) ORDER BY createtime DESC";
		Parameter p1 = new Parameter(Types.INTEGER, uid, ParameterType.Input);
		Parameter p2 = new Parameter(Types.INTEGER, jianglitype1, ParameterType.Input);
		Parameter p3 = new Parameter(Types.INTEGER, jianglitype2, ParameterType.Input);
		CachedRowSet resultSet = SqlHelper.getResultSet(sql, p1,p2,p3);
		try {
			while (resultSet.next()) {
				JiangliLog jll = new JiangliLog();
				jll.id = resultSet.getInt("id");
				jll.uid = resultSet.getInt("uid");
				jll.jianglitype = resultSet.getInt("jianglitype");
				jll.gold = resultSet.getInt("gold");
				jll.createtime = resultSet.getString("createtime");
				jll.paiming = resultSet.getInt("paiming");
				list.add(jll);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
}
